package com.zx.controller;

import com.zx.service.MenuInte;
import com.zx.service.RoleInte;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 程仟磊
 * @date 2021/7/25
 */
@Controller
public class Rolec {
    @Resource
    private RoleInte roleInte;
    @Resource
    private MenuInte menuInte;
    //分页查找角色
    @ResponseBody
    @RequestMapping("/findAllRole")
    public List findAllRole(String page){
        return roleInte.findAllRole(page);
    }
    //查询所有页数
    @ResponseBody
    @RequestMapping("/getRolePages")
    public int getPages(){
        return roleInte.getPages();
    }
    //查询角色没有的权限
    @ResponseBody
    @RequestMapping("/findMneuNoRid")
    public List findMneuNoRid(String rid){
       return  menuInte.findMneuNoRid(rid);
    }
    //划分权限
    @RequestMapping("/addMenuToRole")
    public String getMenuInte(String rid,String[] Menus) {
        roleInte.addMenuToRole(rid,Menus);
        return "list_role";
    }
    //查找角色是否存在
    @ResponseBody
    @RequestMapping("/findRoleByRname")
    public String findRoleByRname(String rname){
        int account = roleInte.findAccount(rname);
        if (account>0){
            return "false";
        }else {
            return "true";
        }
    }
    //添加角色
    @RequestMapping("/addRole")
    public String addRole(String rname){
        roleInte.addRole(rname);
        return "add_role";
    }
    //删除角色
    @RequestMapping("/deleteRole")
    public String deleteRole(String rid){
        roleInte.deleteRole(rid);
        return "list_role";
    }
}
